

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>小说列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="__ICON__">
    <style>
      .layui-card span[lay-separator] {
        margin: 0 10px;
        color: #999;
        font-weight: bold;
      }
      .select-input .select-input-content{
        margin: 0px !important;
        width: 100% !important;
      }
      .select-input .select-input-container {
        height: 38px !important;
        line-height: 38px !important;
      }
      .link{
        color: #01AAED;
      }
      .link-info p{
        font-size: 13px;
      }
      /**
       * 数据表格总高
       */
      .layui-table-body .layui-table-cell {
        height: 85px;
        line-height: 85px;
      }
      /**
      自定义个别td样式
       */
      td .laytable-cell-1-0-1{
        line-height: 21px !important;
      }
      .info p{
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
      }
      .link-info p .iconfont{
        font-size: 15px;
        padding-left: 5px;
      }
      .icon-copy{
        color: #1E9FFF !important;
        cursor: pointer;
      }
    </style>
  </head>

<body>
  <div class="layui-fluid" id="LAY-component-grid-stack">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <blockquote class="layui-elem-quote">
            媒体投放链接请到媒体回传页复制，投放状态停止后，读者请求链接将访问替换书籍；注册关闭后，新用户将不能注册和正常使用App
          </blockquote>
          <div class="layui-form-item">

            <div class="layui-inline">
              <label class="layui-form-label">链接id</label>
              <div class="layui-input-block">
                <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input" value="{$Request.param.id}">
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">token</label>
              <div class="layui-input-block">
              <input type="text" name="token" placeholder="请输入" autocomplete="off" class="layui-input" value="{$Request.param.token}">
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">选择App</label>
              <div class="layui-input-block">
              <select name="quick_id"  lay-search>
                <option value="">请选择</option>
                {foreach $qas as $k => $v}
                <option value="{$v.id}" {if $Request.param.quick_id eq $v.id}selected{/if}>{$v->name}</option>
                {/foreach}
              </select>
              </div>
            </div>

            {if $role->alias != 'channel' && $role->alias != 'agent'}
            <div class="layui-inline">
              <label class="layui-form-label">选择代理</label>
              <div class="layui-input-block">
                <span id="agent"></span>
                <input type="hidden" name="agent_id" id="agent_id" value="">
              </div>
            </div>
            {/if}

            {if $role->alias != 'channel'}
            <div class="layui-inline">
              <label class="layui-form-label">选择投放号</label>
              <div class="layui-input-block">
                <span id="channel"></span>
                <input type="hidden" name="channel_id" id="channel_id" value="">
              </div>
            </div>
            {/if}

            <div class="layui-inline">
              <label class="layui-form-label">小说id</label>
              <div class="layui-input-block">
                <input type="text" name="novel_id" placeholder="请输入" autocomplete="off" class="layui-input" value="{$Request.param.novel_id}">
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label">隐藏状态</label>
              <div class="layui-input-block">
                <select name="is_delete"  lay-search>
                  <option value="">全部</option>
                  <option value="1">已隐藏</option>
                  <option value="0" selected>未隐藏</option>
                </select>
              </div>
            </div>

            <div class="layui-inline">
              <div class="layui-input-block">
                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>
            </div>
          </div>
        </div>


      <div class="layui-card-body">

        <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>

        <script type="text/html" id="linkTpl">
          <div class="link-info">
            <p style="font-weight: bolder;">{{d.name}}</p>
            <p>Id:{{d.id}}  Token:{{d.token}}</p>
            <p>
              <input type="hidden" id="hap_{{d.id}}" value="{{d.hap_link}}">
              <input type="hidden" id="hapjs_{{d.id}}" value="{{d.hapjs_link}}">
              <input type="hidden" id="url_{{d.id}}" value="{{d.h5Link}}">


              hap:<span class="iconfont icon-copy"  onclick="copy('hap','{{d.id}}')"></span>
              hapjs:<span class="iconfont icon-copy" onclick="copy('hapjs','{{d.id}}')"></span>
              url跳转:<span class="iconfont icon-copy" onclick="copy('url','{{d.id}}')"></span>
            </p>
            <p>创建：{{d.create_time}}</p>
          </div>
        </script>

        <script type="text/html" id="novelTpl">
          <div style="font-size: 13px;line-height: 43px;">
              <p style="font-weight: bolder;">{{d.novel.title}}</p>
              <p>第{{d.chapter_no}}章</p>
          </div>
        </script>


        <script type="text/html" id="clickTpl">
          <div style="font-size: 13px;line-height: 43px;">
            <p>{{d.click_uv}}</p>
            <p>新用户占比：{{d.new_fan_ratio}}%</p>
          </div>
        </script>

        <script type="text/html" id="newFanTpl">
          <div style="font-size: 13px;line-height: 27px;">
            <p>{{d.new_fan_num}}</p>
            <p>加桌用户：{{d.jiazhuo_num}}</p>
            <p>加桌率：{{d.jiazhuo_ratio}}%</p>
          </div>
        </script>

        <script type="text/html" id="rechargeTpl">
          <div style="font-size: 13px;line-height: 43px;">
            <p>{{d.recharge_money}}</p>
            <p>笔数：{{d.recharge_count}}</p>
          </div>
        </script>

        <script type="text/html" id="costTpl">
          {{#  if(d.cost > 0){ }}
            <div style="font-size: 13px;line-height: 43px;">
              <p><i class="layui-icon layui-icon-edit" style="color: #1E9FFF;cursor: pointer;font-size: 14px;" onclick="changeCost('{{d.id}}','{{d.cost}}');">{{d.cost}}</i></p>
              <p>回本率：{{d.return_rate}}%</p>
            </div>
          {{#  } else { }}
          <p><i class="layui-icon layui-icon-edit" style="color: #1E9FFF;cursor: pointer;font-size: 14px;"  onclick="changeCost('{{d.id}}','{{d.cost}}');">{{d.cost}}</i></p>
          {{#  } }}
        </script>

        <script type="text/html" id="jiazuoTpl">
          <div style="font-size: 13px;line-height: 30px;">
            <p>
              引导：
              {{#  if(d.enter_pop == 1){ }}
              开启
              {{#  } else { }}
              <span style="color: #FFB800;">关闭</span>
              {{#  } }}
            </p>
            <p>
              强制：
              {{#  if(d.force_switch == 1){ }}
              开启
              {{#  } else { }}
              <span style="color: #FFB800;">关闭</span>
              {{#  } }}
            </p>
            <p>强加章节：{{d.force_chapter_no}}</p>
          </div>



        </script>

        <script type="text/html" id="statusTpl">
          <div style="font-size: 13px;line-height: 43px;">
            <p>投放：<input type="checkbox" name="status{{d.id}}" lay-skin="switch" data-id="{{d.id}}" data-field="status" lay-filter="status"  lay-text="在投|停止" {{#  if(d.status == 1){ }}checked{{#  } }} ></p>
            <p>注册：<input type="checkbox" name="allow_register{{d.id}}" lay-skin="switch" data-id="{{d.id}}"   data-field="allow_register"  lay-filter="status" lay-text="允许|关闭" {{#  if(d.allow_register == 1){ }}checked{{#  } }}></p>
          </div>
        </script>

        <script type="text/html" id="table-useradmin-admin">
          {if $role->alias == 'channel' || $role->alias == 'agent'}
          <div style="line-height: 28px;">
            <p><a href="javascript:;" lay-href="/spread/linkDaily?id={{d.id}}" lay-text="{{d.name}} -分日数据">分日数据</a></p>
            <p><a href="javascript:;" onclick="editLink('{{d.id}}')">修改</a></p>
            <p><a href="javascript:;" onclick="delLink('{{d.id}}', '{{d.name}}')">隐藏</a></p>
          </div>
          {else}
          <div style="line-height: 43px;">
            <p><a href="javascript:;" lay-href="/spread/linkDaily?id={{d.id}}" lay-text="{{d.name}} -分日数据">分日数据</a></p>
            <p><a href="javascript:;" onclick="editLink('{{d.id}}')">修改</a></p>
          </div>
          {/if}
        </script>
      </div>
    </div>
  </div>

  <script src="/static/layuiadmin/layui/layui.js"></script>
  <script src="/static/layui_exts/selectInput.js"></script>
  <script src="/static/layui_exts//axios.min.js"></script>
  <script src="/static/js/clipboard.min.js"></script>

  {if $role->alias == 'channel'}
  {include file="spread/links/channelLinks" /}
  {elseif $role->alias == 'agent' /}
  {include file="spread/links/agentLinks" /}
  {else /}
  {include file="spread/links/defaultLinks" /}
  {/if}
  <script>
    layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index'], function () {
      var $ = layui.$
              , admin = layui.admin
              , form = layui.form;

      form.on('switch(status)', function(data){
        var field = $(data.elem).data('field');
        var id = $(data.elem).data('id');
        if (data.elem.checked){
          var value = 1;
        }else {
          var value = 0;
        }

        admin.req({
          url: '/spread/changeLinkStatus'
          , type: "POST"
          , data: {'id': id, 'field': field, 'value': value}
          , done: function (res) {
            layer.msg('设置成功', {icon: 1, time: 1000}, function () {});
          },not_finish:function (res) {
            layer.msg(res.msg);
          }
        });
      });

    });
  </script>
<script>

  function changeCost(id,cost) {
    layer.prompt({title: '请输入成本，最小单位：元', formType: 3,value: cost}, function(text, index){
      layui.admin.req({
        url: '/spread/changeCost'
        , type: "POST"
        , data: {'id':id,cost:text}
        , done: function (res) {
          layer.msg('修改成功', {icon: 1, time: 1000}, function () {
            layer.closeAll();
            layui.table.reload('LAY-user-back-role');
          });
        },not_finish:function (res) {
          layer.msg(res.msg);
        }
      });
    });
  }

  function editLink(id) {
    layer.open({
      type: 2
      ,title: '修改推广链接'
      ,offset: '15px'
      ,content: '/spread/editLinkInfoForm.html?id='+id
      ,area: ['520px', '670px']
      ,btn: ['确定', '取消']
      ,yes: function(index, layero){
        var iframeWindow = window['layui-layer-iframe'+ index]
                ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

        //监听提交
        iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
          var field = data.field; //获取提交的字段
          //提交 Ajax 成功后，静态更新表格中的数据
          //$.ajax({});
          layui.admin.req({
            url: '/spread/editLink'
            , type: "POST"
            , data: field
            , done: function (res) {
              layer.msg('修改成功', {icon: 1, time: 1000}, function () {
                layer.closeAll();
              });
            },not_finish:function (res) {
              layer.msg(res.msg);
            }
          });
        });
        submit.trigger('click');
      }
    });
  }

  function delLink(id, name) {
    layer.confirm('确定要删除此条【'+name+'】链接吗？', function (index) {
      layui.admin.req({
        url: "{:url('spread/deleteLink')}?id=" + id
        , type: "get"
        , data: {}
        , done: function (res) {
          layer.msg('删除成功', {icon: 1, time: 1000}, function () {
            window.location.reload();
          });
        },not_finish:function (res) {
          layer.msg(res.msg);
        }
      });

    });
  }

  function copy(type,id) {
    var link = layui.$("#"+type+"_"+id).select().val(); // 选择对象
    const textArea = document.createElement('textArea')
    textArea.value = link;
    textArea.style.width = 0
    textArea.style.position = 'fixed'
    textArea.style.left = '-999px'
    textArea.style.top = '10px'
    textArea.setAttribute('readonly', 'readonly')
    document.body.appendChild(textArea)
    textArea.select()
    document.execCommand('copy')
    layer.msg('复制成功', {icon: 1, time: 1000});
    document.body.removeChild(textArea)
  }
</script>
</body>